home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-9.10-netbook-remix-PL.iso / casper / filesystem.squashfs / usr / lib / python2.6 / dist-packages / unohelper.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-10-28  |  13KB  |  317 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import uno
  5. import pyuno
  6. import os
  7. import sys
  8. from com.sun.star.lang import XTypeProvider, XSingleComponentFactory, XServiceInfo
  9. from com.sun.star.uno import RuntimeException, XCurrentContext
  10. from com.sun.star.beans.MethodConcept import ALL as METHOD_CONCEPT_ALL
  11. from com.sun.star.beans.PropertyConcept import ALL as PROPERTY_CONCEPT_ALL
  12. from com.sun.star.reflection.ParamMode import IN as PARAM_MODE_IN, OUT as PARAM_MODE_OUT, INOUT as PARAM_MODE_INOUT
  13. from com.sun.star.beans.PropertyAttribute import MAYBEVOID as PROP_ATTR_MAYBEVOID, BOUND as PROP_ATTR_BOUND, CONSTRAINED as PROP_ATTR_CONSTRAINED, TRANSIENT as PROP_ATTR_TRANSIENT, READONLY as PROP_ATTR_READONLY, MAYBEAMBIGUOUS as PROP_ATTR_MAYBEAMBIGUOUS, MAYBEDEFAULT as PROP_ATTR_MAYBEDEFAULT, REMOVEABLE as PROP_ATTR_REMOVEABLE
  14.  
  15. def _mode_to_str(mode):
  16.     ret = '[]'
  17.     if mode == PARAM_MODE_INOUT:
  18.         ret = '[inout]'
  19.     elif mode == PARAM_MODE_OUT:
  20.         ret = '[out]'
  21.     elif mode == PARAM_MODE_IN:
  22.         ret = '[in]'
  23.     
  24.     return ret
  25.  
  26.  
  27. def _propertymode_to_str(mode):
  28.     ret = ''
  29.     if PROP_ATTR_REMOVEABLE & mode:
  30.         ret = ret + 'removeable '
  31.     
  32.     if PROP_ATTR_MAYBEDEFAULT & mode:
  33.         ret = ret + 'maybedefault '
  34.     
  35.     if PROP_ATTR_MAYBEAMBIGUOUS & mode:
  36.         ret = ret + 'maybeambigous '
  37.     
  38.     if PROP_ATTR_READONLY & mode:
  39.         ret = ret + 'readonly '
  40.     
  41.     if PROP_ATTR_TRANSIENT & mode:
  42.         ret = ret + 'tranient '
  43.     
  44.     if PROP_ATTR_CONSTRAINED & mode:
  45.         ret = ret + 'constrained '
  46.     
  47.     if PROP_ATTR_BOUND & mode:
  48.         ret = ret + 'bound '
  49.     
  50.     if PROP_ATTR_MAYBEVOID & mode:
  51.         ret = ret + 'maybevoid '
  52.     
  53.     return ret.rstrip()
  54.  
  55.  
  56. def inspect(obj, out):
  57.     if isinstance(obj, uno.Type) and isinstance(obj, uno.Char) and isinstance(obj, uno.Bool) and isinstance(obj, uno.ByteSequence) and isinstance(obj, uno.Enum) or isinstance(obj, uno.Any):
  58.         out.write(str(obj) + '\n')
  59.         return None
  60.     ctx = uno.getComponentContext()
  61.     introspection = ctx.ServiceManager.createInstanceWithContext('com.sun.star.beans.Introspection', ctx)
  62.     out.write('Supported services:\n')
  63.     if hasattr(obj, 'getSupportedServiceNames'):
  64.         names = obj.getSupportedServiceNames()
  65.         for ii in names:
  66.             out.write('  ' + ii + '\n')
  67.         
  68.     else:
  69.         out.write('  unknown\n')
  70.     out.write('Interfaces:\n')
  71.     if hasattr(obj, 'getTypes'):
  72.         interfaces = obj.getTypes()
  73.         for ii in interfaces:
  74.             out.write('  ' + ii.typeName + '\n')
  75.         
  76.     else:
  77.         out.write('  unknown\n')
  78.     access = introspection.inspect(obj)
  79.     methods = access.getMethods(METHOD_CONCEPT_ALL)
  80.     out.write('Methods:\n')
  81.     for ii in methods:
  82.         out.write('  ' + ii.ReturnType.Name + ' ' + ii.Name)
  83.         args = ii.ParameterTypes
  84.         infos = ii.ParameterInfos
  85.         out.write('( ')
  86.         for i in range(0, len(args)):
  87.             if i > 0:
  88.                 out.write(', ')
  89.             
  90.             out.write(_mode_to_str(infos[i].aMode) + ' ' + args[i].Name + ' ' + infos[i].aName)
  91.         
  92.         out.write(' )\n')
  93.     
  94.     props = access.getProperties(PROPERTY_CONCEPT_ALL)
  95.     out.write('Properties:\n')
  96.     for ii in props:
  97.         out.write('  (' + _propertymode_to_str(ii.Attributes) + ') ' + ii.Type.typeName + ' ' + ii.Name + '\n')
  98.     
  99.  
  100.  
  101. def createSingleServiceFactory(clazz, implementationName, serviceNames):
  102.     return _FactoryHelper_(clazz, implementationName, serviceNames)
  103.  
  104.  
  105. class _ImplementationHelperEntry:
  106.     
  107.     def __init__(self, ctor, serviceNames):
  108.         self.ctor = ctor
  109.         self.serviceNames = serviceNames
  110.  
  111.  
  112.  
  113. class ImplementationHelper:
  114.     
  115.     def __init__(self):
  116.         self.impls = { }
  117.  
  118.     
  119.     def addImplementation(self, ctor, implementationName, serviceNames):
  120.         self.impls[implementationName] = _ImplementationHelperEntry(ctor, serviceNames)
  121.  
  122.     
  123.     def writeRegistryInfo(self, regKey, smgr):
  124.         for i in self.impls.items():
  125.             keyName = '/' + i[0] + '/UNO/SERVICES'
  126.             key = regKey.createKey(keyName)
  127.             for serviceName in i[1].serviceNames:
  128.                 key.createKey(serviceName)
  129.             
  130.         
  131.         return 1
  132.  
  133.     
  134.     def getComponentFactory(self, implementationName, regKey, smgr):
  135.         entry = self.impls.get(implementationName, None)
  136.         if entry == None:
  137.             raise RuntimeException(implementationName + ' is unknown', None)
  138.         entry == None
  139.         return createSingleServiceFactory(entry.ctor, implementationName, entry.serviceNames)
  140.  
  141.     
  142.     def getSupportedServiceNames(self, implementationName):
  143.         entry = self.impls.get(implementationName, None)
  144.         if entry == None:
  145.             raise RuntimeException(implementationName + ' is unknown', None)
  146.         entry == None
  147.         return entry.serviceNames
  148.  
  149.     
  150.     def supportsService(self, implementationName, serviceName):
  151.         entry = self.impls.get(implementationName, None)
  152.         if entry == None:
  153.             raise RuntimeException(implementationName + ' is unknown', None)
  154.         entry == None
  155.         return serviceName in entry.serviceNames
  156.  
  157.  
  158.  
  159. class ImplementationEntry:
  160.     
  161.     def __init__(self, implName, supportedServices, clazz):
  162.         self.implName = implName
  163.         self.supportedServices = supportedServices
  164.         self.clazz = clazz
  165.  
  166.  
  167.  
  168. def writeRegistryInfoHelper(smgr, regKey, seqEntries):
  169.     for entry in seqEntries:
  170.         keyName = '/' + entry.implName + '/UNO/SERVICES'
  171.         key = regKey.createKey(keyName)
  172.         for serviceName in entry.supportedServices:
  173.             key.createKey(serviceName)
  174.         
  175.     
  176.  
  177.  
  178. def systemPathToFileUrl(systemPath):
  179.     '''returns a file-url for the given system path'''
  180.     return pyuno.systemPathToFileUrl(systemPath)
  181.  
  182.  
  183. def fileUrlToSystemPath(url):
  184.     '''returns a system path (determined by the system, the python interpreter is running on)'''
  185.     return pyuno.fileUrlToSystemPath(url)
  186.  
  187.  
  188. def absolutize(path, relativeUrl):
  189.     '''returns an absolute file url from the given urls'''
  190.     return pyuno.absolutize(path, relativeUrl)
  191.  
  192.  
  193. def getComponentFactoryHelper(implementationName, smgr, regKey, seqEntries):
  194.     for x in seqEntries:
  195.         if x.implName == implementationName:
  196.             return createSingleServiceFactory(x.clazz, implementationName, x.supportedServices)
  197.     
  198.  
  199.  
  200. def addComponentsToContext(toBeExtendedContext, contextRuntime, componentUrls, loaderName):
  201.     smgr = contextRuntime.ServiceManager
  202.     loader = smgr.createInstanceWithContext(loaderName, contextRuntime)
  203.     implReg = smgr.createInstanceWithContext('com.sun.star.registry.ImplementationRegistration', contextRuntime)
  204.     if not os.name == 'nt':
  205.         pass
  206.     isWin = os.name == 'dos'
  207.     isMac = sys.platform == 'darwin'
  208.     for componentUrl in componentUrls:
  209.         reg = smgr.createInstanceWithContext('com.sun.star.registry.SimpleRegistry', contextRuntime)
  210.         reg.open('', 0, 1)
  211.         if not isWin and componentUrl.endswith('.uno'):
  212.             if isMac:
  213.                 componentUrl = componentUrl + '.dylib'
  214.             else:
  215.                 componentUrl = componentUrl + '.so'
  216.         
  217.         implReg.registerImplementation(loaderName, componentUrl, reg)
  218.         rootKey = reg.getRootKey()
  219.         implementationKey = rootKey.openKey('IMPLEMENTATIONS')
  220.         implNames = implementationKey.getKeyNames()
  221.         extSMGR = toBeExtendedContext.ServiceManager
  222.         for x in implNames:
  223.             fac = loader.activate(max(x.split('/')), '', componentUrl, rootKey)
  224.             extSMGR.insert(fac)
  225.         
  226.         reg.close()
  227.     
  228.  
  229. _g_typeTable = { }
  230.  
  231. def _unohelper_getHandle(self):
  232.     ret = None
  233.     if _g_typeTable.has_key(self.__class__):
  234.         ret = _g_typeTable[self.__class__]
  235.     else:
  236.         names = { }
  237.         traverse = list(self.__class__.__bases__)
  238.         while len(traverse) > 0:
  239.             item = traverse.pop()
  240.             bases = item.__bases__
  241.             if uno.isInterface(item):
  242.                 names[item.__pyunointerface__] = None
  243.                 continue
  244.             if len(bases) > 0:
  245.                 traverse = traverse + list(bases)
  246.                 continue
  247.         lst = names.keys()
  248.         types = []
  249.         for x in lst:
  250.             t = uno.getTypeByName(x)
  251.             types.append(t)
  252.         
  253.         ret = (tuple(types), uno.generateUuid())
  254.         _g_typeTable[self.__class__] = ret
  255.     return ret
  256.  
  257.  
  258. class Base(XTypeProvider):
  259.     
  260.     def getTypes(self):
  261.         return _unohelper_getHandle(self)[0]
  262.  
  263.     
  264.     def getImplementationId(self):
  265.         return _unohelper_getHandle(self)[1]
  266.  
  267.  
  268.  
  269. class CurrentContext(XCurrentContext, Base):
  270.     '''a current context implementation, which first does a lookup in the given
  271.        hashmap and if the key cannot be found, it delegates to the predecessor
  272.        if available
  273.     '''
  274.     
  275.     def __init__(self, oldContext, hashMap):
  276.         self.hashMap = hashMap
  277.         self.oldContext = oldContext
  278.  
  279.     
  280.     def getValueByName(self, name):
  281.         if name in self.hashMap:
  282.             return self.hashMap[name]
  283.         if self.oldContext != None:
  284.             return self.oldContext.getValueByName(name)
  285.         return None
  286.  
  287.  
  288.  
  289. class _FactoryHelper_(XSingleComponentFactory, XServiceInfo, Base):
  290.     
  291.     def __init__(self, clazz, implementationName, serviceNames):
  292.         self.clazz = clazz
  293.         self.implementationName = implementationName
  294.         self.serviceNames = serviceNames
  295.  
  296.     
  297.     def getImplementationName(self):
  298.         return self.implementationName
  299.  
  300.     
  301.     def supportsService(self, ServiceName):
  302.         return ServiceName in self.serviceNames
  303.  
  304.     
  305.     def getSupportedServiceNames(self):
  306.         return self.serviceNames
  307.  
  308.     
  309.     def createInstanceWithContext(self, context):
  310.         return self.clazz(context)
  311.  
  312.     
  313.     def createInstanceWithArgumentsAndContext(self, args, context):
  314.         return self.clazz(context, *args)
  315.  
  316.  
  317.